// https://www.acwing.com/problem/content/833/

#include <iostream>
#include <vector>
#include <string>
using namespace std;

vector<int> BuildNextArray(const string& pattern) {
    const auto m = pattern.size();
    vector<int> next(m);
    int j=0;
    for (int i=1; i<m; i++) {
        while (j > 0 && pattern[i] != pattern[j]) {
            j = next[j-1];
        }
        if (pattern[i] == pattern[j]) {
            j++;
        }
        next[i] = j;
    }
    return next;
}

void KMPSearch(const string& pattern, const string& source) {
    const auto m = pattern.size();
    const auto n = source.size();
    vector<int> next = BuildNextArray(pattern);
    int j=0;
    for (int i=0; i<n; i++) {
        while (j > 0 && pattern[j] != source[i]) {
            j = next[j-1];
        }
        if (pattern[j] == source[i]) {
            j++;
        }
        if (j == m) {
            cout<<i-m+1<<" ";
        }
    }
}


int main() {
    int m, n;
    string pattern, source;
    cin>>m>>pattern>>n>>source;
    KMPSearch(pattern, source);
    return 0;
}